package com.example.reschain.demo01.service.impl;

import com.example.reschain.demo01.entity.Order;
import com.example.reschain.demo01.service.OrderHandler;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * @author renyitong
 * @version 1.0.0
 * @createTime 2023年07月28日
 * @Description
 */
@Service
public class CheckAccountHandler implements OrderHandler {

    private OrderHandler next;

    public CheckAccountHandler(@Qualifier("confirmAccountHandler") OrderHandler next) {
        this.next = next;
    }

    /**
     * 检查账户余额
     *
     * @param order
     */
    @Override
    public void handler(Order order) {
        if (Objects.nonNull(order.getUserAccount()) && order.getUserAccount() >= 100) {
            System.out.println("用户余额充足.....");
            next.handler(order);
        } else {
            throw new RuntimeException("用户库存不足100块....");
        }
    }
}
